package com.hz.friends.db;

import java.util.Date;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "ifriends.db";
	private static final int DATABASE_VERSION = 1;
	public static final String TABLE_MESSAGE = "MessageOfChat";
	public static final String TABLE_CONTACTUSER = "DBContactUser";
	
	public DBHelper(Context context) {
		//CursorFactory设置为null,使用默认值
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	//数据库第一次被创建时onCreate会被调用
	@Override
	public void onCreate(SQLiteDatabase db) {
		
	       //  String msgId  String  msgContent int  msgDirection  int msgType  int isRead Date time  DBContactUser fromUser 
		   //String mediaUrl String mediaPath int mediaDuration int imageWidth int imageHeight
		//消息表
		db.execSQL("CREATE TABLE IF NOT EXISTS " +TABLE_MESSAGE+
				"(msgId VARCHAR PRIMARY KEY , msgContent VARCHAR, msgDirection INTEGER, msgType INTEGER,isRead INTEGER,imState INTEGER,time INTEGER,fromUserId VARCHAR," +
				" mediaUrl VARCHAR,mediaPath VARCHAR,mediaDuration INTEGER,imageWidth INTEGER,imageHeight INTEGER)");

		//本地联系人表
		db.execSQL("CREATE TABLE IF NOT EXISTS " +TABLE_CONTACTUSER+
				"(userId VARCHAR PRIMARY KEY , heardUrl VARCHAR, nickName VARCHAR, lastContent VARCHAR,time INTEGER, UNIQUE(userId))");
 
	}

	//如果DATABASE_VERSION值被改为2,系统发现现有数据库版本不同,即会调用onUpgrade
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("ALTER TABLE person ADD COLUMN other STRING");
	}
}
